package com.huluobo.document

import com.huluobo.lib_base.BaseRepo
import com.huluobo.lib_base.Res
import com.huluobo.lib_http.Const
import com.huluobo.lib_http.HttpType
import com.huluobo.lib_http.NetworkFactory
import kotlinx.coroutines.flow.Flow
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
import javax.inject.Inject

/**
 *  Created by LC on 2025/6/27.
 */
class DocumentRepo @Inject constructor() : BaseRepo() {
    private val apiService by lazy { NetworkFactory.factory(HttpType.VIDEO).create(ApiService::class.java) }

    fun uploadDocument(name: String, path: String): Flow<Res<Any>> {
        //封装文件为一个body
        val body = RequestBody.create("application/json;charset=utf-8".toMediaTypeOrNull(), File(path))

        //将body转化为一个part
        val part = MultipartBody.Part.createFormData(Const.PARAM_FILE, name, body)

        return apiService.uploadFile(part)
    }
}